package com.ccp.dev.system.service;
import com.ccp.dev.core.basic.base.BaseService;
import com.ccp.dev.core.basic.util.UUIDUtils;
import com.ccp.dev.system.dao.MessageLogDao;
import com.ccp.dev.system.model.MessageLog;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
/**
 *
 * 消息日志 Service类
 * @author :zxh
 * @Date:2012-11-29 16:24:35
 *
 */
@Service
public class MessageLogService extends BaseService<MessageLog> {
	@Resource
	private MessageLogDao dao;
	//todo 仅有一个无参构造 是否可以删掉
	public MessageLogService() {
	}

	/**
	 * 新增消息日志
	 * @param subject 主题
	 * @param receiver 接受者 ，多个人 ","分隔
	 * @param messageType 消息类型
	 * @param state 状态
	 */
	@Transactional(rollbackFor = Exception.class)
	public void addMessageLog(String subject, String receiver,
							  Integer messageType, Integer state, String tenantId) {
		MessageLog messageLog = new MessageLog();
		messageLog.setId(UUIDUtils.getUUIDFor32());
		messageLog.setSubject(StringUtils.substring(subject, 0, 50));
		messageLog.setReceiver(receiver);
		messageLog.setMessageType(messageType);
		messageLog.setState(state);
		messageLog.setSendTime(new Date());
		messageLog.setTenantId(tenantId);
		dao.add(messageLog);
	}
}
